package com.osti.mytest;

import org.json.JSONObject;
import org.json.JSONTokener;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener
{
	protected static final Context Context = null;
	// class members
	private ImageView	m_BtnPrefs;
	private Intent		m_IntentPrefs;
	private ImageView	m_BtnStart;
	private Intent		m_IntentCntPlayers;
	private ImageView	m_BtnOld;
	private Intent		m_IntentOldTournaments;
	
	// Facebook
	
	//AdMob
	private AdView adView; 

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        //AdMob
        
         //Look up the AdView as a resource and load a request.
        adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
        .build();
        adView.loadAd(adRequest);
        
      
    
        
        // initialize class members
        m_BtnPrefs				= (ImageView)findViewById(R.id.imageView_btnSettings);
        //m_IntentPrefs 		= new Intent(this, ActivityPrefs.class);
        m_IntentPrefs			= new Intent(this, Settings.class);
        m_BtnStart				= (ImageView)findViewById(R.id.imageView_btnStart);
        m_IntentCntPlayers		= new Intent(this, ActivityCntPlayers.class);
        m_BtnOld				= (ImageView)findViewById(R.id.imageView_btnOldTournaments);
        m_IntentOldTournaments	= new Intent(this, ActivityOldTournaments.class);
//        
//        SystemClock.sleep(5000);
//        startActivity(m_IntentCntPlayers);
        
        // Button for "Preferences"
        m_BtnPrefs.setOnClickListener(new View.OnClickListener()
        {
			@Override
			public void onClick(View v)
			{
				m_BtnPrefs.setImageResource(R.drawable.btn_einstellungen_pressed);
				
				 new Handler().postDelayed(new Runnable()
				 {
				        public void run() 
				        {
				        	startActivity(m_IntentPrefs);
				        	m_BtnPrefs.setImageResource(R.drawable.btn_einstellungen_disabled);
				        }
				 }, 100L);    // Change this value to whatever is suitable
			}			
		});
        
        // Button for "Old Tournaments"
        m_BtnOld.setOnClickListener(new View.OnClickListener()
        {
			@Override
			public void onClick(View v)
			{
				m_BtnOld.setImageResource(R.drawable.btn_alteturniere_pressed);
				
				 new Handler().postDelayed(new Runnable()
				 {
				        public void run() 
				        {
				       
				        	Toast.makeText(getApplicationContext(), getString(R.string.oldTournaments_ma), Toast.LENGTH_SHORT).show();
				        	m_BtnOld.setImageResource(R.drawable.btn_alteturniere_disabled);
				        }
				 }, 100L);    // Change this value to whatever is suitable
			}
		});
        
        // Button for "New Match"
        m_BtnStart.setOnClickListener(new View.OnClickListener()
        {
			@Override
			public void onClick(View v)
			{ 
				
				m_BtnStart.setImageResource(R.drawable.btn_neuesspiel_pressed);
				new Handler().postDelayed(new Runnable()
				{
			        public void run() 
			        {
			        	// switch to activity "CntPlayers"
			        	startActivity(m_IntentCntPlayers);
			        	m_BtnStart.setImageResource(R.drawable.btn_neuesspiel_disabled);
			        }
				}, 100L);    // Change this value to whatever is suitable
			}
		});
    }
  
 

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


	@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	protected void onPause() {
		adView.pause();
	    super.onPause();
	}

	@Override
	protected void onResume() {
	    super.onResume();
	    adView.resume();
	}
	
	
}
